package spark.graph
import org.apache.spark.graphx.{Edge, Graph, VertexId}
import org.apache.spark.{SparkConf, SparkContext}

object mapTriplets {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("mapTriplets").setMaster("local")
    val sc = new SparkContext(conf)
    sc.setLogLevel("WARN")
    val users =sc.parallelize(Array((1L, ("Alice", 28)),
      (2L, ("Bob", 27)),
      (3L, ("Charlie", 65)),
      (4L, ("David", 42)),
      (5L, ("Ed", 55)),
      (6L, ("Fran", 50))))
    val relationship = sc.parallelize(Array(
      Edge(2L, 1L, 7),
      Edge(2L, 4L, 2),
      Edge(3L, 2L, 4),
      Edge(3L, 6L, 3),
      Edge(4L, 1L, 1),
      Edge(5L, 2L, 2),
      Edge(5L, 3L, 8),
      Edge(5L, 6L, 3)
    ))
    val defaultUser = ("The Beats",0)
    val graph=Graph(users,relationship,defaultUser)
    graph.edges.collect.foreach(println(_))
    val graph2=graph.mapTriplets(e=>(e.attr,"new Files"))
    graph2.edges.collect.foreach(println(_))

  }
}
